/*
 * Copyright 2025 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/// This is function exists just work around a limitation in winnow, where it
/// can't accumulate `char`s in `escaped_transform`, so this is just a map to
/// all of the valid hex codes that could be provided.
///
/// See: https://github.com/winnow-rs/winnow/discussions/684
pub fn to_str(hex: u32) -> &'static str {
    match hex {
        0x00 => "\x00",
        0x01 => "\x01",
        0x02 => "\x02",
        0x03 => "\x03",
        0x04 => "\x04",
        0x05 => "\x05",
        0x06 => "\x06",
        0x07 => "\x07",
        0x08 => "\x08",
        0x09 => "\x09",
        0x0a => "\x0a",
        0x0b => "\x0b",
        0x0c => "\x0c",
        0x0d => "\x0d",
        0x0e => "\x0e",
        0x0f => "\x0f",
        0x10 => "\x10",
        0x11 => "\x11",
        0x12 => "\x12",
        0x13 => "\x13",
        0x14 => "\x14",
        0x15 => "\x15",
        0x16 => "\x16",
        0x17 => "\x17",
        0x18 => "\x18",
        0x19 => "\x19",
        0x1a => "\x1a",
        0x1b => "\x1b",
        0x1c => "\x1c",
        0x1d => "\x1d",
        0x1e => "\x1e",
        0x1f => "\x1f",
        0x20 => "\x20",
        0x21 => "\x21",
        0x22 => "\x22",
        0x23 => "\x23",
        0x24 => "\x24",
        0x25 => "\x25",
        0x26 => "\x26",
        0x27 => "\x27",
        0x28 => "\x28",
        0x29 => "\x29",
        0x2a => "\x2a",
        0x2b => "\x2b",
        0x2c => "\x2c",
        0x2d => "\x2d",
        0x2e => "\x2e",
        0x2f => "\x2f",
        0x30 => "\x30",
        0x31 => "\x31",
        0x32 => "\x32",
        0x33 => "\x33",
        0x34 => "\x34",
        0x35 => "\x35",
        0x36 => "\x36",
        0x37 => "\x37",
        0x38 => "\x38",
        0x39 => "\x39",
        0x3a => "\x3a",
        0x3b => "\x3b",
        0x3c => "\x3c",
        0x3d => "\x3d",
        0x3e => "\x3e",
        0x3f => "\x3f",
        0x40 => "\x40",
        0x41 => "\x41",
        0x42 => "\x42",
        0x43 => "\x43",
        0x44 => "\x44",
        0x45 => "\x45",
        0x46 => "\x46",
        0x47 => "\x47",
        0x48 => "\x48",
        0x49 => "\x49",
        0x4a => "\x4a",
        0x4b => "\x4b",
        0x4c => "\x4c",
        0x4d => "\x4d",
        0x4e => "\x4e",
        0x4f => "\x4f",
        0x50 => "\x50",
        0x51 => "\x51",
        0x52 => "\x52",
        0x53 => "\x53",
        0x54 => "\x54",
        0x55 => "\x55",
        0x56 => "\x56",
        0x57 => "\x57",
        0x58 => "\x58",
        0x59 => "\x59",
        0x5a => "\x5a",
        0x5b => "\x5b",
        0x5c => "\x5c",
        0x5d => "\x5d",
        0x5e => "\x5e",
        0x5f => "\x5f",
        0x60 => "\x60",
        0x61 => "\x61",
        0x62 => "\x62",
        0x63 => "\x63",
        0x64 => "\x64",
        0x65 => "\x65",
        0x66 => "\x66",
        0x67 => "\x67",
        0x68 => "\x68",
        0x69 => "\x69",
        0x6a => "\x6a",
        0x6b => "\x6b",
        0x6c => "\x6c",
        0x6d => "\x6d",
        0x6e => "\x6e",
        0x6f => "\x6f",
        0x70 => "\x70",
        0x71 => "\x71",
        0x72 => "\x72",
        0x73 => "\x73",
        0x74 => "\x74",
        0x75 => "\x75",
        0x76 => "\x76",
        0x77 => "\x77",
        0x78 => "\x78",
        0x79 => "\x79",
        0x7a => "\x7a",
        0x7b => "\x7b",
        0x7c => "\x7c",
        0x7d => "\x7d",
        0x7e => "\x7e",
        0x7f => "\x7f",
        _ => panic!("unsupported ascii code"),
    }
}
